﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Diagnostics;
using Microsoft.Phone.Scheduler;

namespace Temporizador
{
    public partial class MainPage : PhoneApplicationPage
    {
        private IEnumerable<ScheduledNotification> notifications;

        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        private void RefreshReminders()
        {
            notifications = ScheduledActionService.GetActions<ScheduledNotification>();
            if (notifications.Count() > 0)
            {
                EmptyTextBlock.Visibility = Visibility.Visible;
            }
            else 
            {
                EmptyTextBlock.Visibility = Visibility.Collapsed;
            }
            NotificationListBox.ItemsSource = notifications;
        }

        ///// <summary>
        ///// Refresh the ReminderListBox items when  the page is navigated to.
        ///// </summary>
        ///// <param name="e"></param>
        //protected override void OnNavigatedTo(NavigatingEventArgs e)
        //{
        //    RefreshReminders();
        //}

        private void DeleteReminder(object sender, RoutedEventArgs e)
        {
            string name = (string)((Button)sender).Tag;
            ScheduledActionService.Remove(name);
            RefreshReminders();
        }

        private void NavigateToAddReminder(object sender, EventArgs e)
        {
            //algo
            NavigationService.Navigate(new Uri("/AddNotification.xaml", UriKind.RelativeOrAbsolute));
        }
    }
}